var GameData = require('../module/gameData')();
cc.Class({
    extends: cc.Component,

    properties: {
        clock_sp: cc.Sprite,
        gameT: cc.Label,
        _t: 0,

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this._t = 0;
        this.lifeNum = 90
        this.node.zIndex=1000
        // console.log(GameData.GameLayer.isPause)
    },

    start() {

    },
    playAct() {
        this.gameT.node.color= cc.hexToColor('#E90B0B');
        this.node.getChildByName("clock").getComponent(cc.Sprite).spriteFrame = this.clock_sp.getComponent(cc.Sprite).spriteFrame;
        this.node.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.scaleTo(0.5, 1.3),
                    cc.scaleTo(0.5, 1),
                    // cc.moveBy(0.3,0,20),
                    // cc.moveBy(0.3,0,-20),
                    // cc.moveBy(0.3,0,-20),
                    // cc.moveBy(0.3,0,20),
                )
            )
        )
    },
    update(dt) {
        if (!GameData.isPause) {
            this.node.resumeAllActions();
            this._t += dt;
            if (this._t >= 1) {
                this.lifeNum--;
                this._t = 0;
                if (this.lifeNum == 10) {
                    this.playAct();
                }
                if (this.lifeNum <= 0) {
                    this.lifeNum = 0;
                    this.node.stopAllActions();
                    GameData.GameLayer.isPause = true;
                    GameData.GameLayer.gameOver();
                }
                this.node.getChildByName("clock").getComponent(cc.ProgressBar).progress = this.lifeNum / 90;
                this.gameT.string = this.lifeNum + "";
            }
        } else {
            this.node.pauseAllActions();
        }
    },
});
